package com.tlsy.commerce.model.converter;

import com.tlsy.commerce.model_enum.UserTypeEnum;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * @author Tlsy
 * @version commerce 0.0.1
 * @date 2017/4/19  18:19
 */
@Converter
public class UserTypeConverter implements AttributeConverter<UserTypeEnum,String> {

    public String convertToDatabaseColumn(UserTypeEnum userTypeEnum) {
        if(userTypeEnum==null){
            return null;
        }
        return userTypeEnum.value();
    }

    public UserTypeEnum convertToEntityAttribute(String type) {
        if(type==null){
            return null;
        }
        return UserTypeEnum.fromValue(type);
    }
}
